#pragma once

#include <cassert>
#include <iostream>
namespace sola {

class TimeZone;

#define LOG_TRACE                                                                                                      \
    if (false)                                                                                                         \
    std::cout
#define LOG_DEBUG                                                                                                      \
    if (false)                                                                                                         \
    std::cout
#define LOG_INFO  std::cout << "[INFO] " << __FILE__ << ":" << __LINE__ << " "
#define LOG_WARN  std::cout << "[WARN] " << __FILE__ << ":" << __LINE__ << " "
#define LOG_ERROR std::cout << "[ERROR] " << __FILE__ << ":" << __LINE__ << " "
#define LOG_FATAL                                                                                                      \
    std::cerr << "[FATAL] " << __FILE__ << ":" << __LINE__ << " ";                                                     \
    std::abort()
#define LOG_SYSERR   LOG_ERROR
#define LOG_SYSFATAL LOG_FATAL

// FIXME: This is a simplified version of strerror_tl.
// const char* strerror_tl(int savedErrno) {
//     // This function should return a thread-local cached string for the error message.
//     // For simplicity, we will just use strerror here, but in a real application,
//     // you might want to cache these strings to avoid repeated calls.
//     return std::to_string(savedErrno).c_str();
// };

// 替换原始CHECK_NOTNULL定义
// #define CHECK_NOTNULL(val) assert((val) != nullptr)
#define CHECK_NOTNULL(val) (CheckNotNull(__FILE__, __LINE__, #val, (val)))

template<typename T> T* CheckNotNull(const char* file, int line, const char* names, T* ptr) {
    if (ptr == nullptr) {
        std::cerr << file << ":" << line << " Check failed: " << names << std::endl;
        abort();
    }
    return ptr;
}

} // namespace sola
